package com.china.produce.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2024/1/20
 */
@Service("i.task.test.impl")
public class ITaskTestImpl {

    private List<ITask> iTasks;

    @Autowired(required = false)
    public ITaskTestImpl(List<ITask> iTasks) {

        this.iTasks = iTasks;
    }


    public void test() {
        HashMap<String, List<String>> map = new HashMap<>();

        Optional.of(this.iTasks).orElse(Collections.EMPTY_LIST).forEach(task -> {
            ITask tasks = (ITask) task;
            tasks.getResult().forEach((label, lists) -> {
                map.computeIfAbsent(label, k -> new ArrayList<>()).addAll(lists);
            });
        });

        System.out.println(map);
        Collection<List<String>> values = map.values();
        System.out.println(values);
        List<String> lists = values.stream().flatMap(Collection::stream).collect(Collectors.toList());
        System.out.println(lists);
    }
}
